<?php

namespace app\controller\admin;

use app\BaseController;
use think\App;

class BaseAdmin extends BaseController
{
    protected $admin_id = 0;
    protected $admin;

    protected $param;
    protected $objResult = null;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->initialize();
    }

    protected function initialize()
    {
        $token = request()->header('Authorization');
        if (empty($token)) {
            //兼容特殊组件无法设置header，比如ueditor
            $token = input('Authorization', '', 'trim');
            if (!$token) {
                data_return('登录过期', 401);
            }
        }
        $token = str_replace('Bearer ', '', $token);
        $admin = cache('admin_' . $token);
        if (!$admin) {
            data_return('登录过期', 401);
        } else {
            $this->admin = $admin;//todo 查询数据数据库最新
            $this->admin_id = $admin['admin_id'];
        }
        $this->param = request()->filter('trim,htmlspecialchars')->param();
    }
}
